package com.zhanglu.fun.services.datacenter.token;

import com.zhanglu.fun.services.datacenter.entity.AuthToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @description
 * @Auther zhanglu
 * @Date 2017/9/20 下午1:59
 */
@Service
public class TokenService {
    @Autowired
    private TokenMapper tokenMapper;

    public AuthToken getAuthTokenByToken(String token) {
        return tokenMapper.selectOne(new AuthToken().setToken(token));
    }

    public Boolean addAuthTokenByToken(AuthToken authToken) {
        return tokenMapper.insertSelective(authToken) > 0;
    }

    public Boolean updateAuthTokenByToken(AuthToken authToken) {
        return tokenMapper.updateByPrimaryKeySelective(authToken) > 0;
    }

    public Boolean deleteAuthTokenByToken(String token) {
        return tokenMapper.delete(new AuthToken().setToken(token)) > 0;
    }

    public AuthToken getAuthTokenByUserId(Long userId) {
        return tokenMapper.selectOne(new AuthToken().setUserId(userId));
    }
}
